﻿namespace CodeDDD.Domain.Seedwork
{
    /// <summary>
    /// Base class for entities
    /// </summary>
    public abstract class Entity<TIdentity> : EntityBase
    {
        #region Properties

        /// <summary>
        /// Get the persisten object identifier
        /// </summary>
        public virtual TIdentity Id 
        {
            get
            {
                return (TIdentity)id;
            }
            protected set
            {
                id = value;
            }
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Check if this entity is transient, ie, without identity at this moment
        /// </summary>
        /// <returns>True if entity is transient, else false</returns>
        public override bool IsTransient()
        {
            if (this.Id == null)
                return true;

            return this.Id.Equals(default(TIdentity));
        }
        
        #endregion
    }
}
